module bbo_track_tb;

    localparam NUM_CONTRACTS = 3;
    logic clk_net;
    logic rst_n;

    logic [31:0] bbo_bidprice [NUM_CONTRACTS];
    logic [31:0] bbo_askprice [NUM_CONTRACTS];
    logic [7:0] bbo_bidvolume [NUM_CONTRACTS];
    logic [7:0] bbo_askvolume [NUM_CONTRACTS];
    logic bbo_changed         [NUM_CONTRACTS];
    logic [31:0] rels         [NUM_CONTRACTS];

    logic [31:0] current_bidprice [NUM_CONTRACTS];
    logic [31:0] current_askprice [NUM_CONTRACTS];
    logic [7:0]  current_bidvolume[NUM_CONTRACTS];
    logic [7:0]  current_askvolume[NUM_CONTRACTS];
    logic        fv_recalc_trigger;

    bbo_track UUT ( .* );

    // Initialise clock
    initial clk_net = 0;
    always #5 clk_net = ~clk_net;

    integer i;
    initial begin
        // For Surfer to generate wave file
        $dumpfile("bbo_track_tb.vcd");
        $dumpvars(0,UUT);
        $dumpvars(0, UUT.current_bidprice[0]);
        $dumpvars(0, UUT.current_bidprice[1]);
        $dumpvars(0, UUT.current_bidprice[2]);
        $dumpvars(0, UUT.current_askprice[0]);
        $dumpvars(0, UUT.current_askprice[1]);
        $dumpvars(0, UUT.current_askprice[2]);
        $dumpvars(0, UUT.current_bidvolume[0]);
        $dumpvars(0, UUT.current_bidvolume[1]);
        $dumpvars(0, UUT.current_bidvolume[2]);
        $dumpvars(0, UUT.current_askvolume[0]);
        $dumpvars(0, UUT.current_askvolume[1]);
        $dumpvars(0, UUT.current_askvolume[2]);

        // Initialise
        rst_n = 0;
        for (i = 0; i < NUM_CONTRACTS; i++) begin
            bbo_bidprice[i]  = 0;
            bbo_askprice[i]  = 0;
            bbo_bidvolume[i] = 0;
            bbo_askvolume[i] = 0;
            bbo_changed[i]   = 0;
            rels[i]          = 0;
        end
        rels[1] = 25;
        #10 rst_n = 1;

        // Initialise FV for Royal Gala and send bbo_changed signal
        #10;
        bbo_bidvolume[0] = 13;
        bbo_bidprice[0] =  2500;
        bbo_askvolume[0] = 3;
        bbo_askprice[0] = 2505;
        bbo_changed[0] = 1;

        #10 bbo_changed[0] = 0;

        // Example 1 from the task description file
        // BBO for Granny Smith apples is 2 2520 | 2530 3, should not trigger fv_recalc_trigger
        // BBO for Granny Smith apples is  2 2520 | 2530 3 and Royal Gala change to 13 2500 | 2510 10
        // Should send buy order
        #10;
        bbo_bidvolume[1] = 2;
        bbo_bidprice[1] =  2520;
        bbo_askvolume[1] = 3;
        bbo_askprice[1] = 2530;
        bbo_changed[1] = 1;

        #10 bbo_changed[1] = 0;

        // Test negative logic reset
        #10 rst_n = 0;

        #10;
        
        $finish;

    end

    
endmodule